package battlenetwork;

import java.awt.Point;

public class Grenade extends Thread{

	Point start;
	Point pos;
	Point land;
	double totDiffX;
	
	public Grenade(Point start, Point land){
		this.start = start;
		this.land = land;
		this.totDiffX = Math.abs(start.x-land.x);
	}
	
	public void run(){
		int posX = start.x;
		int vel = 1;
		int direction;
		if(start.x > land.x){
			direction = -1;
		} else {
			direction = 1;
		}
		while(true){
			if(dist(land, pos) < 20){
				break;
			}
			posX = posX + vel*direction;
			pos = new Point(posX, getHeight(posX));
			
		}
	}
	
	public double dist(Point p1, Point p2){
		double diffX = Math.abs(p1.x - p2.x);
		double diffY = Math.abs(p1.y - p2.y);
		return Math.sqrt(Math.pow(diffX, 2) + Math.pow(diffY, 2));
	}
	
	public int getHeight(double x){
		return (int) (-Math.pow(x, 2));
	}
	
}
